package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TCompanyInfo;
import com.ruoyi.system.service.ITCompanyInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司信息Controller
 * 
 * @author kellen
 * @date 2024-04-20
 */
@Controller
@RequestMapping("/system/companyInfo")
public class TCompanyInfoController extends BaseController
{
    private String prefix = "system/companyInfo";

    @Autowired
    private ITCompanyInfoService tCompanyInfoService;

    @RequiresPermissions("system:companyInfo:view")
    @GetMapping()
    public String companyInfo()
    {
        return prefix + "/companyInfo";
    }

    /**
     * 查询公司信息列表
     */
    @RequiresPermissions("system:companyInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TCompanyInfo tCompanyInfo)
    {
        startPage();
        List<TCompanyInfo> list = tCompanyInfoService.selectTCompanyInfoList(tCompanyInfo);
        return getDataTable(list);
    }

    /**
     * 导出公司信息列表
     */
    @RequiresPermissions("system:companyInfo:export")
    @Log(title = "公司信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TCompanyInfo tCompanyInfo)
    {
        List<TCompanyInfo> list = tCompanyInfoService.selectTCompanyInfoList(tCompanyInfo);
        ExcelUtil<TCompanyInfo> util = new ExcelUtil<TCompanyInfo>(TCompanyInfo.class);
        return util.exportExcel(list, "公司信息数据");
    }

    /**
     * 新增公司信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司信息
     */
    @RequiresPermissions("system:companyInfo:add")
    @Log(title = "公司信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TCompanyInfo tCompanyInfo)
    {
        return toAjax(tCompanyInfoService.insertTCompanyInfo(tCompanyInfo));
    }

    /**
     * 修改公司信息
     */
    @RequiresPermissions("system:companyInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TCompanyInfo tCompanyInfo = tCompanyInfoService.selectTCompanyInfoById(id);
        mmap.put("tCompanyInfo", tCompanyInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司信息
     */
    @RequiresPermissions("system:companyInfo:edit")
    @Log(title = "公司信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TCompanyInfo tCompanyInfo)
    {
        return toAjax(tCompanyInfoService.updateTCompanyInfo(tCompanyInfo));
    }

    /**
     * 删除公司信息
     */
    @RequiresPermissions("system:companyInfo:remove")
    @Log(title = "公司信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tCompanyInfoService.deleteTCompanyInfoByIds(ids));
    }
}
